package com.cedarhd.brzx.controller;

import com.cedarhd.brzx.common.JsonResult;
import com.cedarhd.brzx.common.utils.ValidatorUtil;
import com.cedarhd.brzx.domain.service.FileService;
import com.cedarhd.brzx.domain.service.SoaMemberService;
import com.cedarhd.brzx.dto.request.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Evan
 * @date 2018/4/27
 */
@RestController
@Api(value = "通联支付会员绑卡相关接口", description = "通联支付会员绑卡相关接口")
public class SoaMemberCardController {
    private static Logger log = LoggerFactory.getLogger(SoaMemberCardController.class);

    @Autowired
    private SoaMemberService memberService;

    @Autowired
    private FileService fileService;

    //4.1.10
    @RequestMapping(value = Routes.SOA_MEMBER_BANK_CARD_BIN, method = RequestMethod.POST)
    @ApiOperation(value = "查询卡bin", notes = "查询卡bin", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public JsonResult getBindBankBin(@RequestBody GetBankCardBinRequestDTO req) {
        ValidatorUtil.validate(req);
        log.info("createMember params = {}", req);
        JSONObject response = memberService.getBindBankBin(req);
        ValidatorUtil.checkJsonResp(response);
        return JsonResult.getFromResponse(response.toString(), "cardBinInfo");
    }

    //4.1.11
    @RequestMapping(value = Routes.SOA_MEMBER_BANK_CARD_BIND_APPLY, method = RequestMethod.POST)
    @ApiOperation(value = "请求绑定银行卡", notes = "请求绑定银行卡", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public JsonResult applyBindBankCard(@RequestBody ApplyBindBankCardRequestDto req) {
        ValidatorUtil.validate(req);
        log.info("applyBindBankCard params = {}", req);
        JSONObject response = memberService.applyBindBankCard(req);
        ValidatorUtil.checkJsonResp(response);
        return JsonResult.getFromResponse(response.toString());
    }

    //4.1.12
    @RequestMapping(value = Routes.SOA_MEMBER_BANK_CARD_BIND, method = RequestMethod.POST)
    @ApiOperation(value = "确认绑定银行卡", notes = "确认绑定银行卡", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public JsonResult bindBankCard(@RequestBody BindBankCardRequestDto req) {
        ValidatorUtil.validate(req);
        log.info("bindBankCard params = {}", req);
        JSONObject response = memberService.bindBankCard(req);
        ValidatorUtil.checkJsonResp(response);
        return JsonResult.getFromResponse(response.toString());
    }


    //4.1.13
    @RequestMapping(value = Routes.SOA_MEMBER_BANK_CARD_SET_SAFE_CARD, method = RequestMethod.POST)
    @ApiOperation(value = "设置安全卡", notes = "设置安全卡", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public JsonResult setSafeCard(@RequestBody SetSafeCardRequestDto req) {
        ValidatorUtil.validate(req);
        log.info("setSafeCard params = {}", req);
        JSONObject response = memberService.setSafeCard(req);
        ValidatorUtil.checkJsonResp(response);
        return JsonResult.getFromResponse(response.toString());
    }

    //4.1.14
    @RequestMapping(value = Routes.SOA_MEMBER_BANK_CARD_QUERY_SAFE_CARD, method = RequestMethod.POST)
    @ApiOperation(value = "查询绑定银行卡", notes = "查询绑定银行卡", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public JsonResult qreryBankCard(@RequestBody QueryBankCardRequestDto req) {
        ValidatorUtil.validate(req);
        log.info("createMember params = {}", req);
        JSONObject response = memberService.queryBankCard(req);
        ValidatorUtil.checkJsonResp(response);
        return JsonResult.getFromResponse(response.toString());
    }

    //4.1.15
    @RequestMapping(value = Routes.SOA_MEMBER_BANK_CARD_UN_BIND, method = RequestMethod.POST)
    @ApiOperation(value = "解绑绑定银行卡", notes = "解绑绑定银行卡", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public JsonResult unbindBankCard(@RequestBody UnbindBankCardRequestDto req) {
        ValidatorUtil.validate(req);
        log.info("createMember params = {}", req);
        JSONObject response = memberService.unbindBankCard(req);
        ValidatorUtil.checkJsonResp(response);
        return JsonResult.getFromResponse(response.toString());
    }
}
